<!doctype html>
<html lang="en">
<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>言成言成啊</title>
    <link rel="shortcut icon" href="/images/favicon.ico">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/meethigher/cdn@9.0/css/meethigher-font.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/meethigher/cdn@9.0/css/animate.css">
    <link rel="stylesheet" href="/css/index.css">
</head>
<body>
<header class="header">
    <div class="header-menu"><span class="fa fa-bars"></span></div>
    <div class="header-search"><span class="fa fa-search"></span></div>
    <div class="header-title"><a href="/">言成言成啊 | <span class="header-subtitle">Kit Chen&#39;s Blog</span></a></div>
    <ul class="header-navbar clearFix">
        
            <li><a href="/">主页</a></li>
        
            <li><a href="/tags">标签</a></li>
        
            <li><a href="/archives">归档</a></li>
        
            <li><a href="/search">导航</a></li>
        
    </ul>
</header>
<main class="main">
    <div class="main-content meethigher-scroll">
    <article class="post">
        <div class="post-title">
            <h2 class="title">java算法题</h2>
        </div>
        <div class="post-media2">
            <span class="post-time">2019-10-06</span>
            
                <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/algorithm/">algorithm</a></li></ul>
            
        </div>
        <div class="post-content blog-markdown">
            <h3 id="1-Take-a-Ten-Minute-Walk"><a href="#1-Take-a-Ten-Minute-Walk" class="headerlink" title="1. Take a Ten Minute Walk"></a>1. Take a Ten Minute Walk</h3><h5 id="描述"><a href="#描述" class="headerlink" title="描述"></a>描述</h5><figure class="highlight vhdl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">You live <span class="keyword">in</span> the city <span class="keyword">of</span> Cartesia where <span class="keyword">all</span> roads are laid <span class="keyword">out</span> <span class="keyword">in</span> a perfect grid. You arrived ten minutes too early <span class="keyword">to</span> an appointment, so you decided <span class="keyword">to</span> take the opportunity <span class="keyword">to</span> go <span class="keyword">for</span> a short walk. The city provides its citizens <span class="keyword">with</span> a Walk Generating App <span class="keyword">on</span> their phones <span class="comment">-- everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg. ['n', 's', 'w', 'e']). You always walk only a single block in a direction and you know it takes you one minute to traverse one city block, so create a function that will return true if the walk the app gives you will take you exactly ten minutes (you don't want to be early or late!) and will, of course, return you to your starting point. Return false otherwise.</span></span><br><span class="line"></span><br><span class="line"><span class="literal">Note</span>: you will always receive a valid <span class="keyword">array</span> containing a random assortment <span class="keyword">of</span> direction letters (<span class="symbol">'n</span>', <span class="symbol">'s</span>', <span class="symbol">'e</span>', <span class="keyword">or</span> <span class="string">'w'</span> only). It will never give you an empty <span class="keyword">array</span> (that<span class="symbol">'s</span> <span class="keyword">not</span> a walk, that<span class="symbol">'s</span> standing still!).</span><br></pre></td></tr></table></figure>

<h5 id="思路"><a href="#思路" class="headerlink" title="思路"></a>思路</h5><p>判断一个数组长度是否为10，里面n的数量等于s，w的数量等于s，则返回true，否则false</p>
<h5 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案"><a href="#我的解决方案" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TenMinWalk</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isValid</span><span class="params">(<span class="keyword">char</span>[] walk)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">boolean</span> flag=<span class="keyword">true</span>;</span><br><span class="line">		<span class="keyword">int</span>[] directions =<span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">4</span>];</span><br><span class="line">		<span class="keyword">if</span>(walk.length!=<span class="number">10</span>) </span><br><span class="line">			flag=<span class="keyword">false</span>;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; walk.length; i++) &#123;</span><br><span class="line">			<span class="keyword">if</span>(walk[i]==<span class="string">'n'</span>) &#123;</span><br><span class="line">				directions[<span class="number">0</span>]++;</span><br><span class="line">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(walk[i]==<span class="string">'s'</span>) &#123;</span><br><span class="line">				directions[<span class="number">1</span>]++;</span><br><span class="line">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(walk[i]==<span class="string">'e'</span>) &#123;</span><br><span class="line">				directions[<span class="number">2</span>]++;</span><br><span class="line">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(walk[i]==<span class="string">'w'</span>) &#123;</span><br><span class="line">				directions[<span class="number">3</span>]++;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(!(directions[<span class="number">0</span>]==directions[<span class="number">1</span>]&amp;&amp;directions[<span class="number">2</span>]==directions[<span class="number">3</span>]))</span><br><span class="line">			flag=<span class="keyword">false</span>;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">return</span> flag;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案"><a href="#大佬的解决方案" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TenMinWalk</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isValid</span><span class="params">(<span class="keyword">char</span>[] walk)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (walk.length != <span class="number">10</span>) &#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">int</span> x = <span class="number">0</span>, y = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">10</span>; i++) &#123;</span><br><span class="line">      <span class="keyword">switch</span> (walk[i]) &#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'n'</span>:</span><br><span class="line">          y++;</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'e'</span>:</span><br><span class="line">          x++;</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'s'</span>:</span><br><span class="line">          y--;</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="string">'w'</span>:</span><br><span class="line">          x--;</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> x == <span class="number">0</span> &amp;&amp; y == <span class="number">0</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-Find-the-odd-int"><a href="#2-Find-the-odd-int" class="headerlink" title="2. Find the odd int"></a>2. Find the odd int</h3><h5 id="描述-1"><a href="#描述-1" class="headerlink" title="描述"></a>描述</h5><figure class="highlight livecodeserver"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Given <span class="keyword">an</span> array, find <span class="keyword">the</span> int that appears <span class="keyword">an</span> odd <span class="built_in">number</span> <span class="keyword">of</span> times.</span><br><span class="line"></span><br><span class="line">There will always be only <span class="literal">one</span> <span class="keyword">integer</span> that appears <span class="keyword">an</span> odd <span class="built_in">number</span> <span class="keyword">of</span> times.</span><br></pre></td></tr></table></figure>

<h5 id="思路-1"><a href="#思路-1" class="headerlink" title="思路"></a>思路</h5><p>map集合，key存储数字，value存储次数。遍历集合，将value为奇数的key输出</p>
<h5 id="实现-1"><a href="#实现-1" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-1"><a href="#我的解决方案-1" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FindOdd</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">findIt</span><span class="params">(<span class="keyword">int</span>[] a)</span> </span>&#123;</span><br><span class="line">	    Map&lt;Integer,Integer&gt; map=<span class="keyword">new</span> HashMap&lt;Integer,Integer&gt;();</span><br><span class="line">	    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; a.length; i++) &#123;</span><br><span class="line">			map.put(a[i], <span class="number">0</span>);</span><br><span class="line">		&#125;</span><br><span class="line">	    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; a.length; i++) &#123;</span><br><span class="line">	    	<span class="keyword">int</span> count=map.get(a[i]);</span><br><span class="line">	    	++count;</span><br><span class="line">			map.put(a[i], count);</span><br><span class="line">		&#125;</span><br><span class="line">	    <span class="keyword">for</span>(Integer key:map.keySet()) &#123;</span><br><span class="line">	    	<span class="keyword">if</span>(map.get(key)%<span class="number">2</span>==<span class="number">0</span>)</span><br><span class="line">	    		<span class="keyword">continue</span>;</span><br><span class="line">	    	<span class="keyword">return</span> key;</span><br><span class="line">	    &#125;</span><br><span class="line">	    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">	  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-1"><a href="#大佬的解决方案-1" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FindOdd</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">findIt</span><span class="params">(<span class="keyword">int</span>[] A)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> xor = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; A.length; i++) &#123;</span><br><span class="line">      xor ^= A[i];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> xor;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>异或的运算规则：相同为0，不同为1</p>
<p>异或要将运算的两个数字转换为二进制进行运算</p>
<figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 比方说 1⊕2⊕1=2</span></span><br><span class="line"><span class="number">0</span> <span class="number">0</span> <span class="number">0</span> <span class="number">1</span> ----<span class="number">-1</span></span><br><span class="line"><span class="number">0</span> <span class="number">0</span> <span class="number">1</span> <span class="number">0</span> ----<span class="number">-2</span></span><br><span class="line">-------------</span><br><span class="line"><span class="number">0</span> <span class="number">0</span> <span class="number">1</span> <span class="number">1</span> ----<span class="number">-3</span></span><br><span class="line"><span class="number">0</span> <span class="number">0</span> <span class="number">0</span> <span class="number">1</span> ----<span class="number">-1</span></span><br><span class="line">-------------</span><br><span class="line"><span class="number">0</span> <span class="number">0</span> <span class="number">1</span> <span class="number">0</span> ----<span class="number">-2</span></span><br></pre></td></tr></table></figure>

<h3 id="3-Simple-Encryption-1-Alternating-Split"><a href="#3-Simple-Encryption-1-Alternating-Split" class="headerlink" title="3. Simple Encryption #1 - Alternating Split"></a>3. Simple Encryption #1 - Alternating Split</h3><h5 id="描述-2"><a href="#描述-2" class="headerlink" title="描述"></a>描述</h5><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">For</span> building the encrypted string:</span><br><span class="line">Take every 2nd char <span class="keyword">from</span> the string, then the other chars, that are <span class="keyword">not</span> every 2nd char, <span class="keyword">and</span> concat them as new String.</span><br><span class="line"><span class="keyword">Do</span> this n times!</span><br><span class="line"></span><br><span class="line">Examples:</span><br><span class="line"></span><br><span class="line"><span class="string">"This is a test!"</span>, 1 -&gt; <span class="string">"hsi  etTi sats!"</span></span><br><span class="line"><span class="string">"This is a test!"</span>, 2 -&gt; <span class="string">"hsi  etTi sats!"</span> -&gt; <span class="string">"s eT ashi tist!"</span></span><br><span class="line">Write two methods:</span><br><span class="line"></span><br><span class="line">String encrypt(final String text, final int n)</span><br><span class="line">String decrypt(final String encryptedText, final int n)</span><br><span class="line"><span class="keyword">For</span> both methods:</span><br><span class="line"><span class="keyword">If</span> the input-string is <span class="literal">null</span> <span class="keyword">or</span> empty return exactly this value!</span><br><span class="line"><span class="keyword">If</span> n is &lt;= 0 then return the input text.</span><br><span class="line"></span><br><span class="line">This kata is part of the<span class="built_in"> Simple </span>Encryption Series:</span><br><span class="line">Simple Encryption #1 - Alternating Split</span><br><span class="line">Simple Encryption #2 - Index-Difference</span><br><span class="line">Simple Encryption #3 - Turn The Bits Around</span><br><span class="line">Simple Encryption #4 - Qwerty</span><br></pre></td></tr></table></figure>

<h5 id="思路-2"><a href="#思路-2" class="headerlink" title="思路"></a>思路</h5><figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">加密：将字符串转换成字符数组，然后<span class="keyword">String1存储every </span><span class="number">2</span>nd，剩下的给<span class="keyword">String2，然后将String1跟String2拼接起来。</span></span><br><span class="line"><span class="keyword"></span></span><br><span class="line"><span class="keyword">解密：将字符串分割成两部分，即分割成加密中的String1跟String2，然后将String1跟String2依次拼接。</span></span><br></pre></td></tr></table></figure>

<h5 id="实现-2"><a href="#实现-2" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-2"><a href="#我的解决方案-2" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"> <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Kata</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">encrypt</span><span class="params">(<span class="keyword">final</span> String text, <span class="keyword">final</span> <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">if</span>(n&lt;<span class="number">1</span>)</span><br><span class="line">			<span class="keyword">return</span> text;</span><br><span class="line">		String[] arr=text.split(<span class="string">""</span>);</span><br><span class="line">		String str1=<span class="string">""</span>;<span class="comment">//存储every 2nd</span></span><br><span class="line">		String str2=<span class="string">""</span>;</span><br><span class="line">		String str=<span class="string">""</span>;</span><br><span class="line">		<span class="keyword">int</span> m=n;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; arr.length; i++) &#123;</span><br><span class="line">			<span class="keyword">if</span>((i&amp;<span class="number">1</span>)==<span class="number">1</span>) &#123;</span><br><span class="line">				str1+=arr[i];</span><br><span class="line">				<span class="keyword">continue</span>;</span><br><span class="line">			&#125;</span><br><span class="line">			str2+=arr[i];</span><br><span class="line">		&#125;</span><br><span class="line">		str=str1+str2;</span><br><span class="line">		<span class="keyword">if</span>(m&gt;<span class="number">1</span>) </span><br><span class="line">			str=encrypt(str,--m);</span><br><span class="line">		<span class="keyword">return</span> str;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">decrypt</span><span class="params">(<span class="keyword">final</span> String encryptedText, <span class="keyword">final</span> <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">if</span>(n&lt;<span class="number">1</span>)</span><br><span class="line">			<span class="keyword">return</span> encryptedText;</span><br><span class="line">		String[] arr=encryptedText.split(<span class="string">""</span>);</span><br><span class="line">		<span class="keyword">int</span> splitNum=arr.length/<span class="number">2</span>;</span><br><span class="line">		String str1=<span class="string">""</span>;</span><br><span class="line">		String str2=<span class="string">""</span>;</span><br><span class="line">		String str=<span class="string">""</span>;</span><br><span class="line">		<span class="keyword">int</span> m=n;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;splitNum;i++) &#123;</span><br><span class="line">			str2+=arr[i];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=splitNum;i&lt;arr.length;i++) &#123;</span><br><span class="line">			str1+=arr[i];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;splitNum;i++) &#123;</span><br><span class="line">			str+=str1.charAt(i);</span><br><span class="line">			str+=str2.charAt(i);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(str1.length()&gt;str2.length()) &#123;</span><br><span class="line">			str+=str1.charAt(splitNum);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(m&gt;<span class="number">1</span>)</span><br><span class="line">			str=decrypt(str,--m);</span><br><span class="line">		<span class="keyword">return</span> str;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-2"><a href="#大佬的解决方案-2" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Kata</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">encrypt</span><span class="params">(<span class="keyword">final</span> String text, <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">if</span> (n &lt;= <span class="number">0</span> || text == <span class="keyword">null</span> || text.isEmpty()) &#123;</span><br><span class="line">			<span class="keyword">return</span> text;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		StringBuilder firstPart = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">		StringBuilder secondPart = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; text.length(); i++) &#123;</span><br><span class="line">			<span class="keyword">char</span> aChar = text.charAt(i);</span><br><span class="line">			<span class="keyword">if</span> (i % <span class="number">2</span> == <span class="number">1</span>) &#123;</span><br><span class="line">				firstPart.append(aChar);</span><br><span class="line">			&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">				secondPart.append(aChar);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		<span class="keyword">return</span> encrypt(firstPart.append(secondPart).toString(), --n);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">decrypt</span><span class="params">(<span class="keyword">final</span> String encryptedText, <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">if</span> (n &lt;= <span class="number">0</span> || encryptedText == <span class="keyword">null</span> || encryptedText.isEmpty()) &#123;</span><br><span class="line">			<span class="keyword">return</span> encryptedText;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		StringBuilder text = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">		<span class="keyword">final</span> <span class="keyword">int</span> half = encryptedText.length() / <span class="number">2</span>;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; half; i++) &#123;</span><br><span class="line">			text.append(encryptedText.charAt(half + i)).append(encryptedText.charAt(i));</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> (encryptedText.length() % <span class="number">2</span> == <span class="number">1</span>) &#123;</span><br><span class="line">			text.append(encryptedText.charAt(encryptedText.length() - <span class="number">1</span>));</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		<span class="keyword">return</span> decrypt(text.toString(), --n);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>StringBuilder是一个可变的字符序列</p>
<h3 id="4-Maximum-subarray-sum"><a href="#4-Maximum-subarray-sum" class="headerlink" title="4. Maximum subarray sum"></a>4. <a href="https://www.codewars.com/kata/maximum-subarray-sum/train/java" target="_blank" rel="noopener">Maximum subarray sum</a></h3><p>[^时间]: 2019-10-13 周日</p>
<h5 id="描述-3"><a href="#描述-3" class="headerlink" title="描述"></a>描述</h5><figure class="highlight xquery"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">The maximum<span class="built_in"> sum</span> subarray problem consists <span class="keyword">in</span> finding the maximum<span class="built_in"> sum</span> <span class="keyword">of</span> a contiguous<span class="built_in"> subsequence</span> <span class="keyword">in</span> an <span class="keyword">array</span> <span class="keyword">or</span> list <span class="keyword">of</span> integers:</span><br><span class="line"></span><br><span class="line">Max.sequence(new int[]&#123;-<span class="number">2</span>, <span class="number">1</span>, -<span class="number">3</span>, <span class="number">4</span>, -<span class="number">1</span>, <span class="number">2</span>, <span class="number">1</span>, -<span class="number">5</span>, <span class="number">4</span>&#125;);</span><br><span class="line">// should be <span class="number">6</span>: &#123;<span class="number">4</span>, -<span class="number">1</span>, <span class="number">2</span>, <span class="number">1</span>&#125;</span><br><span class="line">Easy <span class="keyword">case</span> <span class="literal">is</span> <span class="keyword">when</span> the list <span class="literal">is</span> made up <span class="keyword">of</span> <span class="keyword">only</span> positive numbers <span class="keyword">and</span> the maximum<span class="built_in"> sum</span> <span class="literal">is</span> the<span class="built_in"> sum</span> <span class="keyword">of</span> the whole <span class="keyword">array</span>. If the list <span class="literal">is</span> made up <span class="keyword">of</span> <span class="keyword">only</span> negative numbers, <span class="keyword">return</span> <span class="number">0</span> instead.</span><br><span class="line"></span><br><span class="line">Empty list <span class="literal">is</span> considered <span class="keyword">to</span> have zero <span class="keyword">greatest</span><span class="built_in"> sum</span>. Note that the<span class="built_in"> empty</span> list <span class="keyword">or</span> <span class="keyword">array</span> <span class="literal">is</span> also a valid sublist/subarray.</span><br></pre></td></tr></table></figure>

<h5 id="思路-3"><a href="#思路-3" class="headerlink" title="思路"></a>思路</h5><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">解决方案：</span><br><span class="line"><span class="number">1.</span> 暴力破解</span><br><span class="line"><span class="number">2.</span> 分治法</span><br><span class="line">分治法的核心思想就是将大问题分解为小问题，再将小问题逐个解决，然后从小问题的解得到原问题的解</span><br><span class="line">如果把数组从任一点（一般取中点）分为两个数组，那最大子数组只能存在于三个位置</span><br><span class="line">a.左数组 b.右数组 <span class="number">3.</span>中间数组（左数组最大后缀和右数组最大前缀的拼接）</span><br><span class="line">然后把分得的两个数组使用递归算法继续进行分割，直到每个子数组只含有一个元素</span><br><span class="line"></span><br><span class="line">太难了，我放弃了</span><br><span class="line"><span class="number">3.</span> 动态规划</span><br></pre></td></tr></table></figure>

<h5 id="实现-3"><a href="#实现-3" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-3"><a href="#我的解决方案-3" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">sequence</span><span class="params">(<span class="keyword">int</span>[] arr)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">int</span> max=-<span class="number">9999</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;arr.length;i++) &#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=i;j&lt;arr.length;j++) &#123;</span><br><span class="line">				<span class="keyword">int</span> sum=<span class="number">0</span>;</span><br><span class="line">				<span class="keyword">for</span>(<span class="keyword">int</span> k=i;k&lt;=j;k++) &#123;</span><br><span class="line">					sum+=arr[k];</span><br><span class="line">				&#125;</span><br><span class="line">				<span class="keyword">if</span>(max&lt;sum)</span><br><span class="line">					max=sum;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> max&lt;<span class="number">0</span>?<span class="number">0</span>:max;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-3"><a href="#大佬的解决方案-3" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Max</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">sequence</span><span class="params">(<span class="keyword">int</span>[] arr)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> max_ending_here = <span class="number">0</span>, max_so_far = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> v : arr) &#123;</span><br><span class="line">            max_ending_here = Math.max(<span class="number">0</span>, max_ending_here + v);</span><br><span class="line">            max_so_far = Math.max(max_so_far, max_ending_here);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> max_so_far;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//可以这样理解</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">sequence</span><span class="params">(<span class="keyword">int</span>[] arr)</span> </span>&#123;</span><br><span class="line">		 <span class="keyword">int</span> max=-<span class="number">9999</span>,cur=<span class="number">0</span>;</span><br><span class="line">		 <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;arr.length;i++) &#123;</span><br><span class="line">			 <span class="keyword">if</span>(cur&lt;<span class="number">0</span>) &#123;</span><br><span class="line">				 cur=arr[i];</span><br><span class="line">			 &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">				 cur+=arr[i];</span><br><span class="line">			 &#125;</span><br><span class="line">			 <span class="keyword">if</span>(cur&gt;=max) &#123;</span><br><span class="line">				 max=cur;</span><br><span class="line">			 &#125;</span><br><span class="line">		 &#125;</span><br><span class="line">		 <span class="keyword">return</span> max&lt;<span class="number">0</span>?<span class="number">0</span>:max;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="5-Double-Cola"><a href="#5-Double-Cola" class="headerlink" title="5. Double Cola"></a>5. <a href="https://www.codewars.com/kata/double-cola/train/java" target="_blank" rel="noopener">Double Cola</a></h3><p>[^时间]: 2019-10-13 周日</p>
<h5 id="描述-4"><a href="#描述-4" class="headerlink" title="描述"></a>描述</h5><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Sheldon, Leonard, Penny, Rajesh <span class="keyword">and</span> Howard are <span class="keyword">in</span> <span class="keyword">the</span> queue <span class="keyword">for</span> a <span class="string">"Double Cola"</span> drink vending machine; there are no other people <span class="keyword">in</span> <span class="keyword">the</span> queue. The <span class="keyword">first</span> one <span class="keyword">in</span> <span class="keyword">the</span> queue (Sheldon) buys a can, drinks <span class="keyword">it</span> <span class="keyword">and</span> doubles! The resulting two Sheldons go <span class="keyword">to</span> <span class="keyword">the</span> <span class="keyword">end</span> <span class="keyword">of</span> <span class="keyword">the</span> queue. Then <span class="keyword">the</span> next <span class="keyword">in</span> <span class="keyword">the</span> queue (Leonard) buys a can, drinks <span class="keyword">it</span> <span class="keyword">and</span> gets <span class="keyword">to</span> <span class="keyword">the</span> <span class="keyword">end</span> <span class="keyword">of</span> <span class="keyword">the</span> queue <span class="keyword">as</span> two Leonards, <span class="keyword">and</span> so <span class="keyword">on</span>.</span><br><span class="line"></span><br><span class="line">For example, Penny drinks <span class="keyword">the</span> <span class="keyword">third</span> can <span class="keyword">of</span> cola <span class="keyword">and</span> <span class="keyword">the</span> queue will look like this:</span><br><span class="line"></span><br><span class="line">Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny</span><br><span class="line">Write a program <span class="keyword">that</span> will <span class="literal">return</span> <span class="keyword">the</span> <span class="built_in">name</span> <span class="keyword">of</span> <span class="keyword">the</span> person who will drink <span class="keyword">the</span> n-th cola.</span><br><span class="line"></span><br><span class="line">Input</span><br><span class="line">The input data consist <span class="keyword">of</span> an array which <span class="keyword">contains</span> <span class="keyword">at</span> least <span class="number">1</span> <span class="built_in">name</span>, <span class="keyword">and</span> single <span class="built_in">integer</span> n which may go <span class="keyword">as</span> high <span class="keyword">as</span> <span class="keyword">the</span> biggest <span class="built_in">number</span> your language <span class="keyword">of</span> choice supports (<span class="keyword">if</span> there's such limit, <span class="keyword">of</span> course).</span><br><span class="line"></span><br><span class="line">Output / Examples</span><br><span class="line">Return <span class="keyword">the</span> single line — <span class="keyword">the</span> <span class="built_in">name</span> <span class="keyword">of</span> <span class="keyword">the</span> person who drinks <span class="keyword">the</span> n-th can <span class="keyword">of</span> cola. The cans are numbered starting <span class="keyword">from</span> <span class="number">1.</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">string</span>[] names = new <span class="built_in">string</span>[] &#123; <span class="string">"Sheldon"</span>, <span class="string">"Leonard"</span>, <span class="string">"Penny"</span>, <span class="string">"Rajesh"</span>, <span class="string">"Howard"</span> &#125;;</span><br><span class="line">Line.WhoIsNext(names, <span class="number">1</span>) == <span class="string">"Sheldon"</span></span><br><span class="line">Line.WhoIsNext(names, <span class="number">52</span>) == <span class="string">"Penny"</span></span><br><span class="line">Line.WhoIsNext(names, <span class="number">7230702951</span>) == <span class="string">"Leonard"</span></span><br></pre></td></tr></table></figure>

<h5 id="思路-4"><a href="#思路-4" class="headerlink" title="思路"></a>思路</h5><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">每到一个人，喝下后会拥有分身术，并且移动到末尾</span><br><span class="line">其实就是一个等比数列，a1=<span class="number">5</span>,q=<span class="number">2</span>,an=<span class="number">5</span>*Math.pow(<span class="number">2</span>,n<span class="number">-1</span>);</span><br><span class="line">等比数列前n项和为 sn=<span class="number">5</span>*Math.pow(<span class="number">2</span>,n)<span class="number">-5</span>;</span><br><span class="line">如果求第六个喝饮料的人，就是<span class="number">6</span>-s1==<span class="number">1</span>,这时候，复制的镜像为copies=Math.pow(<span class="number">2</span>,<span class="number">1</span>)==<span class="number">2</span>;所以<span class="number">1</span>/copies向上取整即为结果</span><br><span class="line">如果求第<span class="number">52</span>个喝饮料的人，就是<span class="number">52</span>-s3==<span class="number">17</span>,这时候，复制的镜像为copies=Math.pow(<span class="number">2</span>,<span class="number">3</span>)==<span class="number">8</span>;所以<span class="number">17</span>/copies向上取整即为结果</span><br></pre></td></tr></table></figure>

<h5 id="实现-4"><a href="#实现-4" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-4"><a href="#我的解决方案-4" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">WhoIsNext</span><span class="params">(String[] names, <span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">int</span> length = names.length;</span><br><span class="line">		<span class="keyword">int</span> i = <span class="number">1</span>;</span><br><span class="line">		<span class="keyword">double</span> sum=<span class="number">0</span>;</span><br><span class="line">		<span class="keyword">if</span> (n &lt; length)</span><br><span class="line">			<span class="keyword">return</span> names[n - <span class="number">1</span>];</span><br><span class="line">		<span class="keyword">while</span> (<span class="keyword">true</span>) &#123;</span><br><span class="line">			sum = <span class="number">5</span> * Math.pow(<span class="number">2</span>, i) - <span class="number">5</span>;</span><br><span class="line">			<span class="keyword">if</span> (sum &gt; n) &#123;</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">			i++;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">double</span> div=n-(<span class="number">5</span>*Math.pow(<span class="number">2</span>, i-<span class="number">1</span>)-<span class="number">5</span>);</span><br><span class="line">		<span class="keyword">double</span> copies=Math.pow(<span class="number">2</span>, i-<span class="number">1</span>);</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">return</span> names[(<span class="keyword">int</span>) Math.ceil(div/copies)-<span class="number">1</span>];</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-4"><a href="#大佬的解决方案-4" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Line</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">WhoIsNext</span><span class="params">(String[] names, <span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    <span class="keyword">while</span> ( n &gt; names.length)&#123;</span><br><span class="line">      n = (n - (names.length - <span class="number">1</span>)) / <span class="number">2</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> names[n-<span class="number">1</span>];</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6-Scramblies"><a href="#6-Scramblies" class="headerlink" title="6. Scramblies"></a>6. <a href="https://www.codewars.com/kata/scramblies/train/java" target="_blank" rel="noopener">Scramblies</a></h3><p>[^时间]: 2019-10-13 周日</p>
<h5 id="描述-5"><a href="#描述-5" class="headerlink" title="描述"></a>描述</h5><figure class="highlight vhdl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Complete the <span class="keyword">function</span> scramble(str1, str2) that returns <span class="literal">true</span> <span class="keyword">if</span> a portion <span class="keyword">of</span> str1 characters can be rearranged <span class="keyword">to</span> match str2, otherwise returns <span class="literal">false</span>.</span><br><span class="line"></span><br><span class="line">Notes:</span><br><span class="line"></span><br><span class="line">Only lower <span class="keyword">case</span> letters will be used (a-z). No punctuation <span class="keyword">or</span> digits will be included.</span><br><span class="line">Performance needs <span class="keyword">to</span> be considered</span><br><span class="line">Input strings s1 <span class="keyword">and</span> s2 are <span class="keyword">null</span> terminated.</span><br><span class="line">Examples</span><br><span class="line">scramble(<span class="symbol">'rkqodlw</span>', <span class="symbol">'world</span>') ==&gt; <span class="literal">True</span></span><br><span class="line">scramble(<span class="symbol">'cedewaraaossoqqyt</span>', <span class="symbol">'codewars</span>') ==&gt; <span class="literal">True</span></span><br><span class="line">scramble(<span class="symbol">'katas</span>', <span class="symbol">'steak</span>') ==&gt; <span class="literal">False</span></span><br></pre></td></tr></table></figure>

<h5 id="思路-5"><a href="#思路-5" class="headerlink" title="思路"></a>思路</h5><figure class="highlight actionscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">判断str1中是否有str2里面的字符。如果有，就把str1中的删掉。没有就直接<span class="literal">false</span></span><br></pre></td></tr></table></figure>

<h5 id="实现-5"><a href="#实现-5" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-5"><a href="#我的解决方案-5" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Scramblies</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">scramble</span><span class="params">(String str1, String str2)</span> </span>&#123;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">boolean</span> flag=<span class="keyword">true</span>;</span><br><span class="line">		StringBuilder strbu2=<span class="keyword">new</span> StringBuilder(str2);</span><br><span class="line">		StringBuilder strbu1=<span class="keyword">new</span> StringBuilder(str1);</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; strbu2.length(); i++) &#123;</span><br><span class="line">			<span class="keyword">int</span> index=strbu1.indexOf(<span class="string">""</span>+strbu2.charAt(i));</span><br><span class="line">			<span class="keyword">if</span>(index&gt;-<span class="number">1</span>) &#123;</span><br><span class="line">				strbu1.delete(index, index+<span class="number">1</span>);</span><br><span class="line">			&#125;<span class="keyword">else</span> &#123;</span><br><span class="line">				flag=<span class="keyword">false</span>;</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> flag;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		System.out.println(scramble(<span class="string">"rkqodlw"</span>, <span class="string">"world"</span>));</span><br><span class="line">		System.out.println(scramble(<span class="string">"cedewaraaossoqqyt"</span>, <span class="string">"codewars"</span>));</span><br><span class="line">		System.out.println(scramble(<span class="string">"katas"</span>, <span class="string">"steak"</span>));</span><br><span class="line">		System.out.println(scramble(<span class="string">"scriptjavx"</span>,<span class="string">"javascript"</span>));<span class="comment">//false</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-5"><a href="#大佬的解决方案-5" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Scramblies</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">scramble</span><span class="params">(String str1, String str2)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (str2.length() &gt; str1.length()) <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        <span class="keyword">for</span> (String s: str2.split(<span class="string">""</span>)) &#123;</span><br><span class="line">          <span class="keyword">if</span> (!str1.contains(s))  <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">          str1 = str1.replaceFirst(s,<span class="string">""</span>);</span><br><span class="line">        &#125;        </span><br><span class="line">       </span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="7-Number-of-trailing-zeros-of-N"><a href="#7-Number-of-trailing-zeros-of-N" class="headerlink" title="7. Number of trailing zeros of N!"></a>7. <a href="https://www.codewars.com/kata/number-of-trailing-zeros-of-n/train/java" target="_blank" rel="noopener">Number of trailing zeros of N!</a></h3><p>[^时间]: 2019-10-13 周日</p>
<h5 id="描述-6"><a href="#描述-6" class="headerlink" title="描述"></a>描述</h5><figure class="highlight livecodeserver"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">Write <span class="keyword">a</span> program that will calculate <span class="keyword">the</span> <span class="built_in">number</span> <span class="keyword">of</span> trailing zeros <span class="keyword">in</span> <span class="keyword">a</span> factorial <span class="keyword">of</span> <span class="keyword">a</span> given <span class="built_in">number</span>.</span><br><span class="line"></span><br><span class="line">N! = <span class="number">1</span> * <span class="number">2</span> * <span class="number">3</span> * ... * N</span><br><span class="line"></span><br><span class="line">Be careful <span class="number">1000</span>! has <span class="number">2568</span> digits...</span><br><span class="line"></span><br><span class="line">For more info, see: <span class="keyword">http</span>://mathworld.wolfram.com/Factorial.html</span><br><span class="line"></span><br><span class="line">Examples</span><br><span class="line">zeros(<span class="number">6</span>) = <span class="number">1</span></span><br><span class="line"><span class="comment"># 6! = 1 * 2 * 3 * 4 * 5 * 6 = 720 --&gt; 1 trailing zero</span></span><br><span class="line"></span><br><span class="line">zeros(<span class="number">12</span>) = <span class="number">2</span></span><br><span class="line"><span class="comment"># 12! = 479001600 --&gt; 2 trailing zeros</span></span><br><span class="line">Hint: You<span class="string">'re not meant to calculate the factorial. Find another way to find the number of zeros.</span></span><br></pre></td></tr></table></figure>

<h5 id="思路-6"><a href="#思路-6" class="headerlink" title="思路"></a>思路</h5><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">这个题一个司马的坑！</span><br><span class="line">我一开始直接求阶乘，int变量接收阶乘，发现，超出了最大范围，即使改成long型，也是一样。</span><br><span class="line">所以就重新开始考虑</span><br><span class="line"><span class="number">6</span>！=<span class="number">6</span>*<span class="number">5</span>*<span class="number">4</span>*<span class="number">3</span>*<span class="number">2</span>*<span class="number">1</span>=<span class="number">720</span>---&gt;<span class="number">1</span></span><br><span class="line"><span class="number">10</span>!=<span class="number">10</span>*<span class="number">9</span>*<span class="number">8</span>*<span class="number">7</span>*<span class="number">6</span>*<span class="number">5</span>*<span class="number">4</span>*<span class="number">3</span>*<span class="number">2</span>*<span class="number">1</span>=<span class="number">3628800</span>---&gt;<span class="number">2</span></span><br><span class="line"><span class="number">14</span>!=<span class="number">14</span>*<span class="number">13</span>*<span class="number">12</span>*<span class="number">11</span>*<span class="number">10</span>*<span class="number">9</span>*<span class="number">8</span>*<span class="number">7</span>*<span class="number">6</span>*<span class="number">5</span>*<span class="number">4</span>*<span class="number">3</span>*<span class="number">2</span>*<span class="number">1</span>=<span class="number">87178291200</span>---&gt;<span class="number">2</span></span><br><span class="line"><span class="number">15</span>!=<span class="number">15</span>*<span class="number">14</span>*<span class="number">13</span>*<span class="number">12</span>*<span class="number">11</span>*<span class="number">10</span>*<span class="number">9</span>*<span class="number">8</span>*<span class="number">7</span>*<span class="number">6</span>*<span class="number">5</span>*<span class="number">4</span>*<span class="number">3</span>*<span class="number">2</span>*<span class="number">1</span>=<span class="number">1307674368000</span>---&gt;<span class="number">3</span></span><br><span class="line">看上面的例子，是不是发现这个司马的坑了？还是这个司马作者牛逼！</span><br></pre></td></tr></table></figure>

<h5 id="实现-6"><a href="#实现-6" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-6"><a href="#我的解决方案-6" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">zeros</span><span class="params">(<span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">int</span> res=<span class="number">0</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">5</span>;i&lt;=n;i*=<span class="number">5</span>) &#123;</span><br><span class="line">			res+=n/i;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> res;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-6"><a href="#大佬的解决方案-6" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">zeros</span><span class="params">(<span class="keyword">int</span> n)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> res = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">5</span>; i &lt;= n; i *= <span class="number">5</span>) &#123;</span><br><span class="line">      res += n / i;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> res;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="8-Range-Extraction"><a href="#8-Range-Extraction" class="headerlink" title="8. Range Extraction"></a>8. <a href="https://www.codewars.com/kata/range-extraction/train/java" target="_blank" rel="noopener">Range Extraction</a></h3><p>[^时间]: 2019-10-19 周六</p>
<h5 id="描述-7"><a href="#描述-7" class="headerlink" title="描述"></a>描述</h5><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">A format for expressing an ordered list of integers is to <span class="keyword">use</span> a comma separated <span class="keyword">list</span> <span class="keyword">of</span> either</span><br><span class="line"></span><br><span class="line">individual integers</span><br><span class="line"><span class="keyword">or</span> a <span class="keyword">range</span> <span class="keyword">of</span> integers denoted <span class="keyword">by</span> the <span class="keyword">starting</span> <span class="built_in">integer</span> separated <span class="keyword">from</span> the <span class="keyword">end</span> <span class="built_in">integer</span> <span class="keyword">in</span> the <span class="keyword">range</span> <span class="keyword">by</span> a dash, <span class="string">'-'</span>. The <span class="keyword">range</span> includes <span class="keyword">all</span> integers <span class="keyword">in</span> the <span class="built_in">interval</span> <span class="keyword">including</span> <span class="keyword">both</span> endpoints. It <span class="keyword">is</span> <span class="keyword">not</span> considered a <span class="keyword">range</span> unless it spans <span class="keyword">at</span> <span class="keyword">least</span> <span class="number">3</span> numbers. <span class="keyword">For</span> example (<span class="string">"12, 13, 15-17"</span>)</span><br><span class="line"><span class="keyword">Complete</span> the solution so that it takes a <span class="keyword">list</span> <span class="keyword">of</span> integers <span class="keyword">in</span> increasing <span class="keyword">order</span> <span class="keyword">and</span> <span class="keyword">returns</span> a correctly formatted <span class="keyword">string</span> <span class="keyword">in</span> the <span class="keyword">range</span> format.</span><br><span class="line"></span><br><span class="line">Example:</span><br><span class="line"></span><br><span class="line">Solution.rangeExtraction(<span class="keyword">new</span> <span class="built_in">int</span>[] &#123;<span class="number">-6</span>, <span class="number">-3</span>, <span class="number">-2</span>, <span class="number">-1</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>, <span class="number">14</span>, <span class="number">15</span>, <span class="number">17</span>, <span class="number">18</span>, <span class="number">19</span>, <span class="number">20</span>&#125;)</span><br><span class="line"><span class="comment"># returns "-6,-3-1,3-5,7-11,14,15,17-20"</span></span><br></pre></td></tr></table></figure>

<h5 id="思路-7"><a href="#思路-7" class="headerlink" title="思路"></a>思路</h5><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">这个题，刚开始理解的时候，有误区。以为连续的数字像<span class="number">3</span>,<span class="number">2</span>,<span class="number">1</span>这种的也算，其实不是，只要<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>这种的才算连续的数字</span><br><span class="line">两个判断<span class="number">1.</span>是否连续 <span class="number">2.</span>连续数字是否&gt;=<span class="number">3</span></span><br><span class="line"></span><br><span class="line">但是向上面这种思维方式，会把简单的问题复杂化。有时候，不能从传统的思维中去考虑。</span><br><span class="line">定义一个变量flag，如果连续，则加一。不连续的时候，就追加相应的数字</span><br></pre></td></tr></table></figure>

<h5 id="实现-7"><a href="#实现-7" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-7"><a href="#我的解决方案-7" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">rangeExtraction</span><span class="params">(<span class="keyword">int</span>[] arr)</span> </span>&#123;</span><br><span class="line">		String list=<span class="string">""</span>;</span><br><span class="line">		<span class="keyword">int</span> flag=<span class="number">0</span>;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; arr.length; i++) &#123;</span><br><span class="line">			<span class="keyword">if</span>(i==arr.length-<span class="number">1</span>||arr[i]+<span class="number">1</span>!=arr[i+<span class="number">1</span>]) &#123;<span class="comment">//前后两个数不连续的时候执行</span></span><br><span class="line">				<span class="keyword">if</span>(flag==<span class="number">0</span>) &#123;</span><br><span class="line">					list+=<span class="string">" "</span>+arr[i];</span><br><span class="line">				&#125;<span class="keyword">else</span> <span class="keyword">if</span>(flag==<span class="number">1</span>) &#123;</span><br><span class="line">					list+=<span class="string">" "</span>+arr[i-<span class="number">1</span>];</span><br><span class="line">					list+=<span class="string">" "</span>+arr[i];</span><br><span class="line">					flag=<span class="number">0</span>;</span><br><span class="line">				&#125;<span class="keyword">else</span> <span class="keyword">if</span>(flag&gt;<span class="number">1</span>) &#123;</span><br><span class="line">					list+=<span class="string">" "</span>+arr[i-flag]+<span class="string">"-"</span>+arr[i];</span><br><span class="line">					flag=<span class="number">0</span>;</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;<span class="keyword">else</span> &#123;<span class="comment">//前后两个数连续的时候执行</span></span><br><span class="line">				flag++;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> list.trim().replace(<span class="string">' '</span>, <span class="string">','</span>);</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-7"><a href="#大佬的解决方案-7" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">static</span> String <span class="title">rangeExtraction</span><span class="params">(<span class="keyword">final</span> <span class="keyword">int</span>[] array)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">final</span> StringBuilder sb = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; array.length; i++) &#123;</span><br><span class="line">            <span class="keyword">int</span> rangeStart = array[i];</span><br><span class="line">            sb.append(rangeStart);</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = i + <span class="number">1</span>; j &lt;= array.length; j++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (j == array.length || array[j] != rangeStart + (j - i)) &#123;</span><br><span class="line">                    <span class="keyword">if</span> (j - i &gt;= <span class="number">3</span>) &#123;</span><br><span class="line">                        sb.append(<span class="string">'-'</span>).append(array[j - <span class="number">1</span>]);</span><br><span class="line">                        i = j - <span class="number">1</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                    sb.append(<span class="string">','</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> sb.deleteCharAt(sb.length() - <span class="number">1</span>).toString();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="9-Weight-for-weight"><a href="#9-Weight-for-weight" class="headerlink" title="9. Weight for weight"></a>9. <a href="https://www.codewars.com/kata/weight-for-weight/train/java" target="_blank" rel="noopener">Weight for weight</a></h3><p>[^时间]: 2019-10-19 周六</p>
<h5 id="描述-8"><a href="#描述-8" class="headerlink" title="描述"></a>描述</h5><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">My friend John <span class="keyword">and</span> I are members <span class="keyword">of</span> <span class="keyword">the</span> <span class="string">"Fat to Fit Club (FFC)"</span>. John <span class="keyword">is</span> worried because each <span class="built_in">month</span> a <span class="built_in">list</span> <span class="keyword">with</span> <span class="keyword">the</span> weights <span class="keyword">of</span> members <span class="keyword">is</span> published <span class="keyword">and</span> each <span class="built_in">month</span> he <span class="keyword">is</span> <span class="keyword">the</span> <span class="keyword">last</span> <span class="keyword">on</span> <span class="keyword">the</span> <span class="built_in">list</span> which means he <span class="keyword">is</span> <span class="keyword">the</span> heaviest.</span><br><span class="line"></span><br><span class="line">I am <span class="keyword">the</span> one who establishes <span class="keyword">the</span> <span class="built_in">list</span> so I told him: <span class="string">"Don't worry any more, I will modify the order of the list"</span>. It was decided <span class="keyword">to</span> attribute a <span class="string">"weight"</span> <span class="keyword">to</span> numbers. The weight <span class="keyword">of</span> a <span class="built_in">number</span> will be <span class="keyword">from</span> now <span class="keyword">on</span> <span class="keyword">the</span> sum <span class="keyword">of</span> <span class="keyword">its</span> digits.</span><br><span class="line"></span><br><span class="line">For example <span class="number">99</span> will have <span class="string">"weight"</span> <span class="number">18</span>, <span class="number">100</span> will have <span class="string">"weight"</span> <span class="number">1</span> so <span class="keyword">in</span> <span class="keyword">the</span> <span class="built_in">list</span> <span class="number">100</span> will come <span class="keyword">before</span> <span class="number">99.</span> Given a <span class="built_in">string</span> <span class="keyword">with</span> <span class="keyword">the</span> weights <span class="keyword">of</span> FFC members <span class="keyword">in</span> normal order can you give this <span class="built_in">string</span> ordered <span class="keyword">by</span> <span class="string">"weights"</span> <span class="keyword">of</span> these numbers?</span><br><span class="line"></span><br><span class="line">Example:</span><br><span class="line"><span class="string">"56 65 74 100 99 68 86 180 90"</span> ordered <span class="keyword">by</span> numbers weights becomes: <span class="string">"100 180 90 56 65 74 68 86 99"</span></span><br><span class="line"></span><br><span class="line">When two numbers have <span class="keyword">the</span> same <span class="string">"weight"</span>, let us <span class="built_in">class</span> them <span class="keyword">as</span> <span class="keyword">if</span> they were strings <span class="keyword">and</span> <span class="keyword">not</span> numbers: <span class="number">100</span> <span class="keyword">is</span> <span class="keyword">before</span> <span class="number">180</span> because <span class="keyword">its</span> <span class="string">"weight"</span> (<span class="number">1</span>) <span class="keyword">is</span> <span class="keyword">less than</span> <span class="keyword">the</span> one <span class="keyword">of</span> <span class="number">180</span> (<span class="number">9</span>) <span class="keyword">and</span> <span class="number">180</span> <span class="keyword">is</span> <span class="keyword">before</span> <span class="number">90</span> <span class="keyword">since</span>, having <span class="keyword">the</span> same <span class="string">"weight"</span> (<span class="number">9</span>), <span class="keyword">it</span> <span class="keyword">comes before</span> <span class="keyword">as</span> a <span class="built_in">string</span>.</span><br><span class="line"></span><br><span class="line">All numbers <span class="keyword">in</span> <span class="keyword">the</span> <span class="built_in">list</span> are positive numbers <span class="keyword">and</span> <span class="keyword">the</span> <span class="built_in">list</span> can be empty.</span><br><span class="line"></span><br><span class="line">Notes</span><br><span class="line"><span class="keyword">it</span> may happen <span class="keyword">that</span> <span class="keyword">the</span> input <span class="built_in">string</span> have leading, trailing whitespaces <span class="keyword">and</span> more than a unique whitespace <span class="keyword">between</span> two consecutive numbers</span><br><span class="line">Don't modify <span class="keyword">the</span> input</span><br><span class="line">For C: The <span class="literal">result</span> <span class="keyword">is</span> freed.</span><br></pre></td></tr></table></figure>

<h5 id="思路-8"><a href="#思路-8" class="headerlink" title="思路"></a>思路</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">老子不会做！</span><br></pre></td></tr></table></figure>

<h5 id="实现-8"><a href="#实现-8" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-8"><a href="#我的解决方案-8" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">orderWeight</span><span class="params">(String string)</span> </span>&#123;</span><br><span class="line">		ArrayList&lt;String&gt; list=<span class="keyword">new</span> ArrayList&lt;String&gt;(Arrays.asList(string.split(<span class="string">" "</span>)));</span><br><span class="line">		String temp;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; list.size(); i++) &#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;list.size()-<span class="number">1</span>;j++) &#123;</span><br><span class="line">				<span class="keyword">if</span>(getWeight(list.get(j))&gt;getWeight(list.get(j+<span class="number">1</span>))) &#123;</span><br><span class="line">					temp=list.get(j);</span><br><span class="line">					list.set(j, list.get(j+<span class="number">1</span>));</span><br><span class="line">					list.set(j+<span class="number">1</span>, temp);</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		String str=<span class="string">""</span>;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; list.size(); i++) &#123;</span><br><span class="line">			str+=<span class="string">" "</span>+list.get(i);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> str.trim();</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-8"><a href="#大佬的解决方案-8" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">orderWeight</span><span class="params">(String string)</span> </span>&#123;</span><br><span class="line">    String[] split = string.split(<span class="string">" "</span>);</span><br><span class="line">    Arrays.sort(split, <span class="keyword">new</span> Comparator&lt;String&gt;() &#123;</span><br><span class="line">      <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">compare</span><span class="params">(String a, String b)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> aWeight = a.chars().map(c -&gt; Character.getNumericValue(c)).sum();</span><br><span class="line">        <span class="keyword">int</span> bWeight = b.chars().map(c -&gt; Character.getNumericValue(c)).sum();</span><br><span class="line">        <span class="keyword">return</span> aWeight - bWeight != <span class="number">0</span> ? aWeight - bWeight : a.compareTo(b);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="keyword">return</span> String.join(<span class="string">" "</span>, split);</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<h3 id="10-Is-my-friend-cheating"><a href="#10-Is-my-friend-cheating" class="headerlink" title="10. Is my friend cheating?"></a>10. <a href="https://www.codewars.com/kata/is-my-friend-cheating/train/java" target="_blank" rel="noopener">Is my friend cheating?</a></h3><p>[^时间]: 2019-10-19 周六</p>
<h5 id="描述-9"><a href="#描述-9" class="headerlink" title="描述"></a>描述</h5><figure class="highlight xquery"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">A friend <span class="keyword">of</span> mine takes a sequence <span class="keyword">of</span> numbers from <span class="number">1</span> <span class="keyword">to</span> n (<span class="keyword">where</span> n &gt; <span class="number">0</span>).</span><br><span class="line">Within that sequence, he chooses two numbers, a <span class="keyword">and</span> b.</span><br><span class="line">He says that the product <span class="keyword">of</span> a <span class="keyword">and</span> b should be equal <span class="keyword">to</span> the<span class="built_in"> sum</span> <span class="keyword">of</span> all numbers <span class="keyword">in</span> the sequence, excluding a <span class="keyword">and</span> b.</span><br><span class="line">Given a<span class="built_in"> number</span> n, could you tell me the numbers he excluded from the sequence?</span><br><span class="line">The <span class="keyword">function</span> takes the parameter: n (n <span class="literal">is</span> always strictly greater than <span class="number">0</span>) <span class="keyword">and</span> returns an <span class="keyword">array</span> <span class="keyword">or</span> a<span class="built_in"> string</span> (depending on the language) <span class="keyword">of</span> the form:</span><br><span class="line"></span><br><span class="line">[(a, b), ...] <span class="keyword">or</span> [[a, b], ...] <span class="keyword">or</span> &#123;&#123;a, b&#125;, ...&#125; <span class="keyword">or</span> <span class="keyword">or</span> [&#123;a, b&#125;, ...]</span><br><span class="line">with all (a, b) which are the possible removed numbers <span class="keyword">in</span> the sequence <span class="number">1</span> <span class="keyword">to</span> n.</span><br><span class="line"></span><br><span class="line">[(a, b), ...] <span class="keyword">or</span> [[a, b], ...] <span class="keyword">or</span> &#123;&#123;a, b&#125;, ...&#125; <span class="keyword">or</span> ...will be sorted <span class="keyword">in</span> increasing <span class="keyword">order</span> <span class="keyword">of</span> the <span class="string">"a"</span>.</span><br><span class="line"></span><br><span class="line">It happens that there are several possible (a, b). The <span class="keyword">function</span> returns an<span class="built_in"> empty</span> <span class="keyword">array</span> (<span class="keyword">or</span> an<span class="built_in"> empty</span><span class="built_in"> string</span>) <span class="keyword">if</span> no possible numbers are found which will prove that my friend has<span class="built_in"> not</span> told the truth! (Go: <span class="keyword">in</span> this <span class="keyword">case</span> <span class="keyword">return</span> nil).</span><br><span class="line"></span><br><span class="line">(See examples <span class="keyword">of</span> returns <span class="keyword">for</span> each language <span class="keyword">in</span> <span class="string">"RUN SAMPLE TESTS"</span>)</span><br><span class="line"></span><br><span class="line">Examples:</span><br><span class="line">removNb(<span class="number">26</span>) should <span class="keyword">return</span> [(<span class="number">15</span>, <span class="number">21</span>), (<span class="number">21</span>, <span class="number">15</span>)]</span><br><span class="line"><span class="keyword">or</span></span><br><span class="line"></span><br><span class="line">removNb(<span class="number">26</span>) should <span class="keyword">return</span> &#123; &#123;<span class="number">15</span>, <span class="number">21</span>&#125;, &#123;<span class="number">21</span>, <span class="number">15</span>&#125; &#125;</span><br><span class="line"><span class="keyword">or</span></span><br><span class="line"></span><br><span class="line">removeNb(<span class="number">26</span>) should <span class="keyword">return</span> [[<span class="number">15</span>, <span class="number">21</span>], [<span class="number">21</span>, <span class="number">15</span>]]</span><br><span class="line"><span class="keyword">or</span></span><br><span class="line"></span><br><span class="line">removNb(<span class="number">26</span>) should <span class="keyword">return</span> [ &#123;<span class="number">15</span>, <span class="number">21</span>&#125;, &#123;<span class="number">21</span>, <span class="number">15</span>&#125; ]</span><br><span class="line"><span class="keyword">or</span></span><br><span class="line"></span><br><span class="line">removNb(<span class="number">26</span>) should <span class="keyword">return</span> <span class="string">"15 21, 21 15"</span></span><br><span class="line"><span class="keyword">or</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">in</span> C:</span><br><span class="line">removNb(<span class="number">26</span>) should <span class="keyword">return</span>  **an <span class="keyword">array</span> <span class="keyword">of</span> pairs &#123;&#123;<span class="number">15</span>, <span class="number">21</span>&#125;&#123;<span class="number">21</span>, <span class="number">15</span>&#125;&#125;**</span><br><span class="line">tested <span class="keyword">by</span> way <span class="keyword">of</span> strings.</span><br></pre></td></tr></table></figure>

<h5 id="思路-9"><a href="#思路-9" class="headerlink" title="思路"></a>思路</h5><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">从<span class="number">1</span>-n的n个数中，找到<span class="number">2</span>个数<span class="selector-tag">a</span>,<span class="selector-tag">b</span>,使得除去<span class="selector-tag">a</span>,<span class="selector-tag">b</span>,剩下的数之和与a，b之积相等</span><br></pre></td></tr></table></figure>

<h5 id="实现-9"><a href="#实现-9" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-9"><a href="#我的解决方案-9" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> source;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"><span class="keyword">import</span> java.util.Scanner;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RemovedNumbers</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 超时了</span></span><br><span class="line"><span class="comment">//	public static List&lt;long[]&gt; removNb(long n) &#123;</span></span><br><span class="line"><span class="comment">//		List&lt;long[]&gt; list=new ArrayList&lt;long[]&gt;();</span></span><br><span class="line"><span class="comment">//		long sum = n * (1 + n) / 2;</span></span><br><span class="line"><span class="comment">//		for (long i = 1; i &lt;= n; i++) &#123;</span></span><br><span class="line"><span class="comment">//			for (long j = 1; j &lt;= n; j++) &#123;</span></span><br><span class="line"><span class="comment">//				if(i*j==(sum-i-j))</span></span><br><span class="line"><span class="comment">//					list.add(new long[] &#123;</span></span><br><span class="line"><span class="comment">//						i,j</span></span><br><span class="line"><span class="comment">//					&#125;);	</span></span><br><span class="line"><span class="comment">//			&#125;</span></span><br><span class="line"><span class="comment">//		&#125;</span></span><br><span class="line"><span class="comment">//		// your code</span></span><br><span class="line"><span class="comment">//		return list;</span></span><br><span class="line"><span class="comment">//	&#125;</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">public</span> <span class="keyword">static</span> List&lt;<span class="keyword">long</span>[]&gt; removNb(<span class="keyword">long</span> n) &#123;</span><br><span class="line">		List&lt;<span class="keyword">long</span>[]&gt; list = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">		<span class="keyword">long</span> sum = n * (<span class="number">1</span> + n) / <span class="number">2</span>;</span><br><span class="line">		<span class="keyword">for</span> (<span class="keyword">long</span> i = <span class="number">1</span>; i &lt;= n; i++) &#123;</span><br><span class="line">			<span class="keyword">long</span> j = (sum - i) / (i + <span class="number">1</span>);</span><br><span class="line">			<span class="keyword">if</span> (j &gt;= <span class="number">1</span> &amp;&amp; j &lt;= n &amp;&amp; i * j == (sum - i - j)) &#123;</span><br><span class="line">				list.add(<span class="keyword">new</span> <span class="keyword">long</span>[] &#123;</span><br><span class="line">						i,j</span><br><span class="line">				&#125;);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> list;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		Scanner input = <span class="keyword">new</span> Scanner(System.in);</span><br><span class="line">		<span class="keyword">int</span> n = input.nextInt();</span><br><span class="line">		System.out.println(removNb(n));</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-9"><a href="#大佬的解决方案-9" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.LinkedList;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RemovedNumbers</span> </span>&#123;</span><br><span class="line">  <span class="comment">/*</span></span><br><span class="line"><span class="comment">  We desire: ab = 1 + ... + n - a - b</span></span><br><span class="line"><span class="comment">  Take advantage of b = sum - a</span></span><br><span class="line"><span class="comment">                        -------</span></span><br><span class="line"><span class="comment">                         a + 1</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> LinkedList&lt;<span class="keyword">long</span>[]&gt; removNb(<span class="keyword">long</span> n) &#123;</span><br><span class="line">    LinkedList&lt;<span class="keyword">long</span>[]&gt; numbers = <span class="keyword">new</span> LinkedList&lt;<span class="keyword">long</span>[]&gt;();</span><br><span class="line">    <span class="keyword">long</span> sum = (n * n + n) / <span class="number">2</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">long</span> a = <span class="number">1</span>; a &lt; n; a++) &#123;</span><br><span class="line">      <span class="keyword">double</span> b = (sum - a) / (<span class="keyword">double</span>) (a + <span class="number">1</span>);</span><br><span class="line">      <span class="keyword">if</span> (b &lt;= n &amp;&amp; b % <span class="number">1</span> == <span class="number">0</span>) &#123;</span><br><span class="line">        numbers.add(<span class="keyword">new</span> <span class="keyword">long</span>[] &#123;a, (<span class="keyword">long</span>) b&#125;);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> numbers;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我居然发现我的思路，跟大佬的思路是一样的，看来我也是大佬了，嘎嘎嘎</p>
<h3 id="11-Longest-Common-Subsequence"><a href="#11-Longest-Common-Subsequence" class="headerlink" title="11. Longest Common Subsequence "></a>11. <a href="https://www.codewars.com/kata/longest-common-subsequence/train/java" target="_blank" rel="noopener">Longest Common Subsequence </a></h3><p>[^时间]: 2019-10-27 周日</p>
<h5 id="描述-10"><a href="#描述-10" class="headerlink" title="描述"></a>描述</h5><figure class="highlight vhdl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">Write a <span class="keyword">function</span> called LCS that accepts two sequences <span class="keyword">and</span> returns the longest subsequence common <span class="keyword">to</span> the passed <span class="keyword">in</span> sequences.</span><br><span class="line"></span><br><span class="line">Subsequence</span><br><span class="line">A subsequence <span class="keyword">is</span> different from a substring. The terms <span class="keyword">of</span> a subsequence need <span class="keyword">not</span> be consecutive terms <span class="keyword">of</span> the original <span class="keyword">sequence</span>.</span><br><span class="line"></span><br><span class="line">Example subsequence</span><br><span class="line">Subsequences <span class="keyword">of</span> <span class="string">"abc"</span> = <span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>, <span class="string">"ab"</span>, <span class="string">"ac"</span>, <span class="string">"bc"</span> <span class="keyword">and</span> <span class="string">"abc"</span>.</span><br><span class="line"></span><br><span class="line">LCS examples</span><br><span class="line">Solution.lcs(<span class="string">"abcdef"</span>, <span class="string">"abc"</span>) =&gt; returns <span class="string">"abc"</span></span><br><span class="line">Solution.lcs(<span class="string">"abcdef"</span>, <span class="string">"acf"</span>) =&gt; returns <span class="string">"acf"</span></span><br><span class="line">Solution.lcs(<span class="string">"132535365"</span>, <span class="string">"123456789"</span>) =&gt; returns <span class="string">"12356"</span></span><br><span class="line">Notes</span><br><span class="line">Both arguments will be strings</span><br><span class="line"><span class="keyword">Return</span> value must be a <span class="built_in">string</span></span><br><span class="line"><span class="keyword">Return</span> an empty <span class="built_in">string</span> <span class="keyword">if</span> there exists no common subsequence</span><br><span class="line">Both arguments will have one <span class="keyword">or</span> more characters (<span class="keyword">in</span> JavaScript)</span><br><span class="line"><span class="keyword">All</span> tests will only have a single longest common subsequence. Don<span class="symbol">'t</span> worry about cases such as LCS( <span class="string">"1234"</span>, <span class="string">"3412"</span> ), which would have two possible longest common subsequences: <span class="string">"12"</span> <span class="keyword">and</span> <span class="string">"34"</span>.</span><br><span class="line"><span class="literal">Note</span> that the Haskell variant will <span class="keyword">use</span> randomized testing, but any longest common subsequence will be valid.</span><br><span class="line"></span><br><span class="line"><span class="literal">Note</span> that the OCaml variant <span class="keyword">is</span> using <span class="keyword">generic</span> lists instead <span class="keyword">of</span> strings, <span class="keyword">and</span> will also have randomized tests (any longest common subsequence will be valid).</span><br><span class="line"></span><br><span class="line">Tips</span><br><span class="line">Wikipedia has an explanation <span class="keyword">of</span> the two properties that can be used <span class="keyword">to</span> solve the problem:</span><br><span class="line"></span><br><span class="line">First <span class="keyword">property</span></span><br><span class="line">Second <span class="keyword">property</span></span><br></pre></td></tr></table></figure>

<h5 id="思路-10"><a href="#思路-10" class="headerlink" title="思路"></a>思路</h5><figure class="highlight erlang-repl"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">这个问题，soeasy!就是两个字符串比较共有的最长的子串呗</span><br></pre></td></tr></table></figure>

<h5 id="实现-10"><a href="#实现-10" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-10"><a href="#我的解决方案-10" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-10"><a href="#大佬的解决方案-10" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="12-Is-my-friend-cheating"><a href="#12-Is-my-friend-cheating" class="headerlink" title="12. Is my friend cheating?"></a>12. <a href="https://www.codewars.com/kata/is-my-friend-cheating/train/java" target="_blank" rel="noopener">Is my friend cheating?</a></h3><p>[^时间]: 2019-10-27 周日</p>
<h5 id="描述-11"><a href="#描述-11" class="headerlink" title="描述"></a>描述</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="思路-11"><a href="#思路-11" class="headerlink" title="思路"></a>思路</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="实现-11"><a href="#实现-11" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-11"><a href="#我的解决方案-11" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-11"><a href="#大佬的解决方案-11" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="13-Is-my-friend-cheating"><a href="#13-Is-my-friend-cheating" class="headerlink" title="13. Is my friend cheating?"></a>13. <a href="https://www.codewars.com/kata/is-my-friend-cheating/train/java" target="_blank" rel="noopener">Is my friend cheating?</a></h3><p>[^时间]: 2019-10-27 周日</p>
<h5 id="描述-12"><a href="#描述-12" class="headerlink" title="描述"></a>描述</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="思路-12"><a href="#思路-12" class="headerlink" title="思路"></a>思路</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h5 id="实现-12"><a href="#实现-12" class="headerlink" title="实现"></a>实现</h5><h6 id="我的解决方案-12"><a href="#我的解决方案-12" class="headerlink" title="我的解决方案"></a>我的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h6 id="大佬的解决方案-12"><a href="#大佬的解决方案-12" class="headerlink" title="大佬的解决方案"></a>大佬的解决方案</h6><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
        </div>
        
            <div class="busuanzi">
                <span id="busuanzi_container_page_pv">阅读量<span id="busuanzi_value_page_pv"></span>次</span>
                <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            </div>
        
    </article>
</div>
    <pointer href="javascript:void(0);" class="arrow fa fa-arrow-up"></pointer>
<pointer href="javascript:void(0);" class="arrow fa fa-arrow-down"></pointer>

</main>
<aside class="aside">
    <div class="aside-content">
        <div class="aside-avatar"><img src="/images/kitchen.jpg" alt="言成"></div>
        <div class="aside-author">言成</div>
        <div class="aside-description">爱学习，爱运动，爱看妹子</div>
        <ul class="aside-contact clearFix">
            <li><span class="fa fa-github"></span><a href="https://github.com/meethigher">Github</a></li>
            <li><span class="fa fa-envelope"></span><a href="javascript:void(0);">meethigher@qq.com</a></li>
            <li><span class="fa fa-weixin"></span><a href="javascript:void(0);"><img src="/images/weixin.png" alt="扫描微信二维码，加我哦！"></a></li>
        </ul>
    </div>
</aside>
<div class="toolbar"><span class="fa fa-th"></span></div>
<div id="particles-js"></div>
<script src="https://cdn.jsdelivr.net/gh/meethigher/cdn@9.0/js/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/meethigher/cdn@9.0/js/particles.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/meethigher/cdn@9.0/js/app.js"></script>
<script src="/js/meethigher.js"></script>
<script src="/js/toolbar.js"></script>
</body>
</html>